/**
 * 作者: clz
 * 日期: 2025-04-05 11:28:08
 * 备注: 联盟信息
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 公会id
	protected String name = ""; // 名称
	protected int level; // 等级
	protected String icon = ""; // 旗帜头像 (对应 union_decorate表ID - 1-1)
	protected long createUserId; // 创建者id
	protected long createTime; // 创建时间
	protected int exp; // 经验
	protected long masterId; // 会长id
	protected String masterName = ""; // 会长名称
	protected long power; // 公会总收益
	protected int limitType; // 限制条件是否审批 (0不限制，1验证)
	protected int limitLevel; // 限制条件等级
	protected int limitLevelOpen; // 限制条件等级开关
	protected String notice = ""; // 公告
	protected String des = ""; // 联盟宣言
	protected int contribution; // 公会总贡献 (联盟资金)
	protected int memberNum; // 成员数量
	protected int serverId; // 服务器id
	protected byte isRenameFree; // 是否免费改名 (1可以免费改名)
	protected byte isReiconFree; // 是否免费更换头像 (1可以免费更改)
	protected String tagList = ""; // 联盟标签 (1;2;3)
	protected String shortName = ""; // 简称
	protected int decorationId; // 地标装饰Id (默认为0)

	public void reset() {
	}

	protected String getKey() {
		return "UnionInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_info"));
	}

	public JsonObject insert() {
		if (this.level == 0) {
			putLevel(1);
		}
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 公会id
		obj.put("name", name); // 名称
		obj.put("level", level); // 等级
		obj.put("icon", icon); // 旗帜头像 (对应 union_decorate表ID - 1-1)
		obj.put("createUserId", createUserId); // 创建者id
		obj.put("createTime", createTime); // 创建时间
		obj.put("exp", exp); // 经验
		obj.put("masterId", masterId); // 会长id
		obj.put("masterName", masterName); // 会长名称
		obj.put("power", power); // 公会总收益
		obj.put("limitType", limitType); // 限制条件是否审批 (0不限制，1验证)
		obj.put("limitLevel", limitLevel); // 限制条件等级
		obj.put("limitLevelOpen", limitLevelOpen); // 限制条件等级开关
		obj.put("notice", notice); // 公告
		obj.put("des", des); // 联盟宣言
		obj.put("contribution", contribution); // 公会总贡献 (联盟资金)
		obj.put("memberNum", memberNum); // 成员数量
		obj.put("serverId", serverId); // 服务器id
		obj.put("isRenameFree", isRenameFree); // 是否免费改名 (1可以免费改名)
		obj.put("isReiconFree", isReiconFree); // 是否免费更换头像 (1可以免费更改)
		obj.put("tagList", tagList); // 联盟标签 (1;2;3)
		obj.put("shortName", shortName); // 简称
		obj.put("decorationId", decorationId); // 地标装饰Id (默认为0)
		return obj;
	}

	public PBUnionInfo.Builder takeInitBuilder() {
		PBUnionInfo.Builder sb = PBUnionInfo.newBuilder();
		if (id != 0) {
			sb.setId(id);
		}
		if (!name.isEmpty()) {
			sb.setName(name);
		}
		if (level != 0) {
			sb.setLevel(level);
		}
		if (!icon.isEmpty()) {
			sb.setIcon(icon);
		}
		if (exp != 0) {
			sb.setExp(exp);
		}
		if (masterId != 0) {
			sb.setMasterId(masterId);
		}
		if (!masterName.isEmpty()) {
			sb.setMasterName(masterName);
		}
		if (power != 0) {
			sb.setPower(power);
		}
		if (limitType != 0) {
			sb.setLimitType(limitType);
		}
		if (limitLevel != 0) {
			sb.setLimitLevel(limitLevel);
		}
		if (limitLevelOpen != 0) {
			sb.setLimitLevelOpen(limitLevelOpen);
		}
		if (!notice.isEmpty()) {
			sb.setNotice(notice);
		}
		if (!des.isEmpty()) {
			sb.setDes(des);
		}
		if (contribution != 0) {
			sb.setContribution(contribution);
		}
		if (memberNum != 0) {
			sb.setMemberNum(memberNum);
		}
		if (serverId != 0) {
			sb.setServerId(serverId);
		}
		if (isRenameFree != 0) {
			sb.setIsRenameFree(isRenameFree);
		}
		if (isReiconFree != 0) {
			sb.setIsReiconFree(isReiconFree);
		}
		if (!tagList.isEmpty()) {
			sb.setTagList(tagList);
		}
		if (!shortName.isEmpty()) {
			sb.setShortName(shortName);
		}
		if (decorationId != 0) {
			sb.setDecorationId(decorationId);
		}
		return sb;
	}

	public PBUnionInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUnionInfo.Builder sb = PBUnionInfo.newBuilder();
		if (isFieldUpdate("id")) {
			sb.setId(id);
		}
		if (isFieldUpdate("name")) {
			sb.setName(name);
		}
		if (isFieldUpdate("level")) {
			sb.setLevel(level);
		}
		if (isFieldUpdate("icon")) {
			sb.setIcon(icon);
		}
		if (isFieldUpdate("exp")) {
			sb.setExp(exp);
		}
		if (isFieldUpdate("masterId")) {
			sb.setMasterId(masterId);
		}
		if (isFieldUpdate("masterName")) {
			sb.setMasterName(masterName);
		}
		if (isFieldUpdate("power")) {
			sb.setPower(power);
		}
		if (isFieldUpdate("limitType")) {
			sb.setLimitType(limitType);
		}
		if (isFieldUpdate("limitLevel")) {
			sb.setLimitLevel(limitLevel);
		}
		if (isFieldUpdate("limitLevelOpen")) {
			sb.setLimitLevelOpen(limitLevelOpen);
		}
		if (isFieldUpdate("notice")) {
			sb.setNotice(notice);
		}
		if (isFieldUpdate("des")) {
			sb.setDes(des);
		}
		if (isFieldUpdate("contribution")) {
			sb.setContribution(contribution);
		}
		if (isFieldUpdate("memberNum")) {
			sb.setMemberNum(memberNum);
		}
		if (isFieldUpdate("serverId")) {
			sb.setServerId(serverId);
		}
		if (isFieldUpdate("isRenameFree")) {
			sb.setIsRenameFree(isRenameFree);
		}
		if (isFieldUpdate("isReiconFree")) {
			sb.setIsReiconFree(isReiconFree);
		}
		if (isFieldUpdate("tagList")) {
			sb.setTagList(tagList);
		}
		if (isFieldUpdate("shortName")) {
			sb.setShortName(shortName);
		}
		if (isFieldUpdate("decorationId")) {
			sb.setDecorationId(decorationId);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public String getName() {
		return name;
	}

	public void putName(String name) {
		if (!this.name.equals(name)) {
			this.name = name;
			updateRedisHashField(getKey(), "name", this.name);
		}
	}

	public int getLevel() {
		return level;
	}

	public void putLevel(int level) {
		if (this.level != level) {
			this.level = level;
			updateRedisHashField(getKey(), "level", this.level);
		}
	}

	public void addLevel(int value) {
		this.level += value;
		updateRedisHashField(getKey(), "level", this.level);
	}

	public String getIcon() {
		return icon;
	}

	public void putIcon(String icon) {
		if (!this.icon.equals(icon)) {
			this.icon = icon;
			updateRedisHashField(getKey(), "icon", this.icon);
		}
	}

	public long getCreateUserId() {
		return createUserId;
	}

	public void putCreateUserId(long createUserId) {
		if (this.createUserId != createUserId) {
			this.createUserId = createUserId;
			updateRedisHashField(getKey(), "createUserId", this.createUserId);
		}
	}

	public void addCreateUserId(long value) {
		this.createUserId += value;
		updateRedisHashField(getKey(), "createUserId", this.createUserId);
	}

	public long getCreateTime() {
		return createTime;
	}

	public void putCreateTime(long createTime) {
		if (this.createTime != createTime) {
			this.createTime = createTime;
			updateRedisHashField(getKey(), "createTime", this.createTime);
		}
	}

	public void addCreateTime(long value) {
		this.createTime += value;
		updateRedisHashField(getKey(), "createTime", this.createTime);
	}

	public int getExp() {
		return exp;
	}

	public void putExp(int exp) {
		if (this.exp != exp) {
			this.exp = exp;
			updateRedisHashField(getKey(), "exp", this.exp);
		}
	}

	public void addExp(int value) {
		this.exp += value;
		updateRedisHashField(getKey(), "exp", this.exp);
	}

	public long getMasterId() {
		return masterId;
	}

	public void putMasterId(long masterId) {
		if (this.masterId != masterId) {
			this.masterId = masterId;
			updateRedisHashField(getKey(), "masterId", this.masterId);
		}
	}

	public void addMasterId(long value) {
		this.masterId += value;
		updateRedisHashField(getKey(), "masterId", this.masterId);
	}

	public String getMasterName() {
		return masterName;
	}

	public void putMasterName(String masterName) {
		if (!this.masterName.equals(masterName)) {
			this.masterName = masterName;
			updateRedisHashField(getKey(), "masterName", this.masterName);
		}
	}

	public long getPower() {
		return power;
	}

	public void putPower(long power) {
		if (this.power != power) {
			this.power = power;
			updateRedisHashField(getKey(), "power", this.power);
		}
	}

	public void addPower(long value) {
		this.power += value;
		updateRedisHashField(getKey(), "power", this.power);
	}

	public int getLimitType() {
		return limitType;
	}

	public void putLimitType(int limitType) {
		if (this.limitType != limitType) {
			this.limitType = limitType;
			updateRedisHashField(getKey(), "limitType", this.limitType);
		}
	}

	public void addLimitType(int value) {
		this.limitType += value;
		updateRedisHashField(getKey(), "limitType", this.limitType);
	}

	public int getLimitLevel() {
		return limitLevel;
	}

	public void putLimitLevel(int limitLevel) {
		if (this.limitLevel != limitLevel) {
			this.limitLevel = limitLevel;
			updateRedisHashField(getKey(), "limitLevel", this.limitLevel);
		}
	}

	public void addLimitLevel(int value) {
		this.limitLevel += value;
		updateRedisHashField(getKey(), "limitLevel", this.limitLevel);
	}

	public int getLimitLevelOpen() {
		return limitLevelOpen;
	}

	public void putLimitLevelOpen(int limitLevelOpen) {
		if (this.limitLevelOpen != limitLevelOpen) {
			this.limitLevelOpen = limitLevelOpen;
			updateRedisHashField(getKey(), "limitLevelOpen", this.limitLevelOpen);
		}
	}

	public void addLimitLevelOpen(int value) {
		this.limitLevelOpen += value;
		updateRedisHashField(getKey(), "limitLevelOpen", this.limitLevelOpen);
	}

	public String getNotice() {
		return notice;
	}

	public void putNotice(String notice) {
		if (!this.notice.equals(notice)) {
			this.notice = notice;
			updateRedisHashField(getKey(), "notice", this.notice);
		}
	}

	public String getDes() {
		return des;
	}

	public void putDes(String des) {
		if (!this.des.equals(des)) {
			this.des = des;
			updateRedisHashField(getKey(), "des", this.des);
		}
	}

	public int getContribution() {
		return contribution;
	}

	public void putContribution(int contribution) {
		if (this.contribution != contribution) {
			this.contribution = contribution;
			updateRedisHashField(getKey(), "contribution", this.contribution);
		}
	}

	public void addContribution(int value) {
		this.contribution += value;
		updateRedisHashField(getKey(), "contribution", this.contribution);
	}

	public int getMemberNum() {
		return memberNum;
	}

	public void putMemberNum(int memberNum) {
		if (this.memberNum != memberNum) {
			this.memberNum = memberNum;
			updateRedisHashField(getKey(), "memberNum", this.memberNum);
		}
	}

	public void addMemberNum(int value) {
		this.memberNum += value;
		updateRedisHashField(getKey(), "memberNum", this.memberNum);
	}

	public int getServerId() {
		return serverId;
	}

	public void putServerId(int serverId) {
		if (this.serverId != serverId) {
			this.serverId = serverId;
			updateRedisHashField(getKey(), "serverId", this.serverId);
		}
	}

	public void addServerId(int value) {
		this.serverId += value;
		updateRedisHashField(getKey(), "serverId", this.serverId);
	}

	public byte getIsRenameFree() {
		return isRenameFree;
	}

	public void putIsRenameFree(byte isRenameFree) {
		if (this.isRenameFree != isRenameFree) {
			this.isRenameFree = isRenameFree;
			updateRedisHashField(getKey(), "isRenameFree", this.isRenameFree);
		}
	}

	public void addIsRenameFree(byte value) {
		this.isRenameFree += value;
		updateRedisHashField(getKey(), "isRenameFree", this.isRenameFree);
	}

	public byte getIsReiconFree() {
		return isReiconFree;
	}

	public void putIsReiconFree(byte isReiconFree) {
		if (this.isReiconFree != isReiconFree) {
			this.isReiconFree = isReiconFree;
			updateRedisHashField(getKey(), "isReiconFree", this.isReiconFree);
		}
	}

	public void addIsReiconFree(byte value) {
		this.isReiconFree += value;
		updateRedisHashField(getKey(), "isReiconFree", this.isReiconFree);
	}

	public String getTagList() {
		return tagList;
	}

	public void putTagList(String tagList) {
		if (!this.tagList.equals(tagList)) {
			this.tagList = tagList;
			updateRedisHashField(getKey(), "tagList", this.tagList);
		}
	}

	public String getShortName() {
		return shortName;
	}

	public void putShortName(String shortName) {
		if (!this.shortName.equals(shortName)) {
			this.shortName = shortName;
			updateRedisHashField(getKey(), "shortName", this.shortName);
		}
	}

	public int getDecorationId() {
		return decorationId;
	}

	public void putDecorationId(int decorationId) {
		if (this.decorationId != decorationId) {
			this.decorationId = decorationId;
			updateRedisHashField(getKey(), "decorationId", this.decorationId);
		}
	}

	public void addDecorationId(int value) {
		this.decorationId += value;
		updateRedisHashField(getKey(), "decorationId", this.decorationId);
	}

}